package com.example.mapper;

import com.example.entity.Appointment;
import com.example.entity.AppointmentHourCount;
import com.example.vo.AppointmentVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.util.List;

/**
 * 预约Mapper
 */
@Mapper
public interface AppointmentMapper {
    
    /**
     * 插入预约记录
     */
    int insert(Appointment appointment);
    
    /**
     * 根据ID更新预约记录
     */
    int updateById(Appointment appointment);
    
    /**
     * 根据ID删除预约记录（逻辑删除）
     */
    int deleteById(Long id);
    
    /**
     * 根据ID查询预约记录
     */
    Appointment selectById(Long id);
    
    /**
     * 根据用户ID查询预约列表
     */
    List<Appointment> selectByUserId(@Param("userId") Long userId);
    
    /**
     * 根据店长ID查询预约列表
     */
    List<Appointment> selectByStoreManagerId(@Param("storeManagerId") Long storeManagerId);

    /**
     * 店长预约条件查询
     */
    List<AppointmentVO> selectStoreManagerAppointments(@Param("storeManagerId") Long storeManagerId,
                                                      @Param("startDate") String startDate,
                                                      @Param("endDate") String endDate,
                                                      @Param("status") Integer status,
                                                      @Param("serviceType") String serviceType);
    
    /**
     * 根据店长ID、日期和时间查询预约数量
     */
    int countByStoreManagerAndDateTime(@Param("storeManagerId") Long storeManagerId,
                                      @Param("appointmentDate") LocalDate appointmentDate,
                                      @Param("appointmentHour") Integer appointmentHour);
    
    /**
     * 根据用户ID、店长ID、日期和时间查询预约
     */
    Appointment selectByUserAndDateTime(@Param("userId") Long userId,
                                       @Param("storeManagerId") Long storeManagerId,
                                       @Param("appointmentDate") LocalDate appointmentDate,
                                       @Param("appointmentHour") Integer appointmentHour);
    
    /**
     * 分页查询预约记录
     */
    List<Appointment> selectPage(@Param("offset") int offset,
                                @Param("size") int size,
                                @Param("userId") Long userId,
                                @Param("storeManagerId") Long storeManagerId,
                                @Param("status") Integer status,
                                @Param("startDate") LocalDate startDate,
                                @Param("endDate") LocalDate endDate);
    
    /**
     * 查询预约记录总数
     */
    long selectCount(@Param("userId") Long userId,
                    @Param("storeManagerId") Long storeManagerId,
                    @Param("status") Integer status,
                    @Param("startDate") LocalDate startDate,
                    @Param("endDate") LocalDate endDate);
    
    /**
     * 查询店长在指定日期各个时间段的已预约数量
     */
    List<AppointmentHourCount> countByStoreManagerAndDate(@Param("storeManagerId") Long storeManagerId,
                                                         @Param("appointmentDate") LocalDate appointmentDate);
    
    /**
     * 管理员分页查询所有预约记录
     */
    List<AppointmentVO> selectAdminAppointmentPage(@Param("username") String username,
                                                  @Param("storeManagerName") String storeManagerName,
                                                  @Param("status") Integer status,
                                                  @Param("packageName") String packageName,
                                                  @Param("startDate") String startDate,
                                                  @Param("endDate") String endDate);
    
    /**
     * 管理员查询预约记录总数
     */
    long selectAdminAppointmentCount(@Param("username") String username,
                                    @Param("storeManagerName") String storeManagerName,
                                    @Param("status") Integer status,
                                    @Param("packageName") String packageName,
                                    @Param("startDate") String startDate,
                                    @Param("endDate") String endDate);
} 